package com.lagou.hdfs;

import org.apache.hadoop.conf.Configuration;
import com.lagou.hdfs.SortMapper;
import com.lagou.hdfs.SortReduce;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

/**
 * ClassName: SortDriver <br/>
 * Description: <br/>
 * date: 2020/9/1 3:50 下午<br/>
 *
 * @author colde<br />
 */
public class SortDriver {

    public static void main(String[] args) throws ClassNotFoundException,
            IOException, InterruptedException {
        // 1 获取配置信息，或者job对象实例
        Configuration configuration = new Configuration();
        Job job = Job.getInstance(configuration);
        // 2 指定本程序的jar包所在的本地路径
        job.setJarByClass(SortDriver.class);
        // 3 指定本业务job要使用的mapper/Reducer业务类
        job.setMapperClass(SortMapper.class);
        job.setReducerClass(SortReduce.class);
        // 4 指定mapper输出数据的kv类型
        job.setMapOutputKeyClass(LongWritable.class);
        job.setMapOutputValueClass(NullWritable.class);
        // 5 指定最终输出的数据的kv类型
        //        map()方法输出kv;key-->bean对象，value-->NullWritable.get()；
        job.setOutputKeyClass(LongWritable.class);
        job.setOutputValueClass(NullWritable.class);
        // 6 指定job的输入原始文件所在目录
        FileInputFormat.setInputPaths(job, new Path("C:/Users/001226/Desktop/lagou/hadoop-test/hadoop/files/file1.txt"),new Path("C:/Users/001226/Desktop/lagou/hadoop-test/hadoop/files/file2.txt"),new Path("C:/Users/001226/Desktop/lagou/hadoop-test/hadoop/files/file3.txt"));
        FileOutputFormat.setOutputPath(job, new Path("C:/Users/001226/Desktop/lagou/hadoop-test/hadoop/out"));
        // 7 将job中配置的相关参数，以及job所用的java类所在的jar包， 提交给yarn去运行
        boolean result = job.waitForCompletion(true);
        System.exit(result ? 0 : 1);
    }
}
